#!/usr/bin/env bash
#
downloadfonts() {
  fontdir=fonttmp
  [[ ! -d $fontdir ]] && mkdir -p $fontdir
  pushd $fontdir || exit
  [[ ! -f UbuntuMono.tar.xz ]] && wget https://github.com/ryanoasis/nerd-fonts/releases/download/v3.0.1/UbuntuMono.tar.xz
  sudo mkdir -p /usr/share/fonts/truetype/UbuntuMono
  xz -d xzvf UbuntuMono.tar.xz
  tar xvf UbuntuMono.tar
  sudo mv *.ttf /usr/share/fonts/truetype/UbuntuMono

  wget https://github.com/ryanoasis/nerd-fonts/releases/download/v3.0.1/CascadiaCode.tar.xz
  xz -d CascadiaCode.tar.xz
  tar xvf CascadiaCode.tar
  sudo mkdir -p /usr/share/fonts/truetype/CascadiaCode
  sudo mv *.ttf /usr/share/fonts/truetype/CascadiaCode
  sudo fc-cache -f -v
  popd || exit
  exit
}
apt() {
  sudo sed -i "s@http://.*archive.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list
  sudo sed -i "s@http://.*security.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list
  curl -sL https://deb.nodesource.com/setup_18.x -o nodesource_setup.sh
  sudo apt-get update
  sudo apt-get install -y nodejs
}
while getopts "fa" f; do
  case "$f" in
  f) downloadfonts ;;
  a) apt ;;
  *) ;;
  esac
done
#curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
if [[ "$(uname)" == "Linux" ]]; then

  sudo apt install -y silversearcher-ag
  sudo apt install -y git
  sudo apt install -y gcc
  sudo apt install -y cmake
  sudo apt install -y clang
  sudo apt install -y clangd
  sudo apt install -y python3-pip
  sudo apt install -y python3-venv
  pip3 install neovim --user
  pip install neovim --user
  sudo pip install -y pynvim
  sudo apt install -y openvpn
  sudo apt install -y curl
  sudo apt install -y ranger
  sudo apt-get install -y sqlite3 libsqlite3-dev # Ubuntu
  sudo apt install -y zsh
  sudo apt install -y fzf
else
  echo "macos"
fi
sudo npm install -g neovim
npm install --global yarn
curl -sS https://starship.rs/install.sh | sh
pip install pynvim
